package com.tanhua.manage.controller;

import com.tanhua.manage.service.DashboardService;
import com.tanhua.manage.vo.DistributionVo;
import com.tanhua.manage.vo.Summary;
import com.tanhua.manage.vo.YearVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/management/dashboard")
public class DashboardController {

    @Autowired
    private DashboardService dashboardService;

    @GetMapping("summary")
    public ResponseEntity<Summary> querySummary(@RequestHeader("Authorization") String token){
        try {
            Summary summary =  dashboardService.querySummary();
            if (summary !=null){
                return ResponseEntity.ok(summary);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
    /**
     * 新增、活跃用户、次日留存率
     *
     * @param sd
     * @param ed
     * @param type
     */
    @GetMapping("users")
    public YearVo queryData(@RequestParam("sd") Long sd,
                            @RequestParam("ed") Long ed,
                            @RequestParam("type") Integer type) {


        return this.dashboardService.queryData(sd, ed, type);
    }


    /**
     * 注册用户分布，行业top、年龄、性别、地区
     *
     * @param sd
     * @param ed
     * @return
     */
    @GetMapping("distribution")
    public DistributionVo queryDistribution(@RequestParam("sd") Long sd, @RequestParam("ed") Long ed) {

        return this.dashboardService.queryDistribution(sd, ed);

    }
}
